<template>
<div class="tab-control">
  <div class="tab-control-item"
       :class="{active: idx === currentIndex}"
       v-for="(item, idx) in title"
       @click="itemClick(idx)"
  >
    <span>{{item}}</span>
  </div>
</div>
</template>

<script>
export default {
  name: 'TabControl',
  props: {
    title: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    itemClick(idx) {
      this.currentIndex = idx;
      this.$emit('tabClick',idx);
    }
  }
}
</script>

<style scoped>
.tab-control {
  display: flex;
  text-align: center;
  font-size: 15px;
  height: 40px;
  line-height: 40px;

}
.tab-control-item {
  flex: 1;
}

.tab-control-item span {
  padding: 5px;
}

.active span {
  color: var(--color-tint);
  border-bottom: 3px solid var(--color-tint);
}
</style>
